package code20210926;

public class C213 {

	public static void main(String[] args) {
		int[] nums = {1};
		System.out.println(new C213().rob(nums));
	}
	public int rob(int[] nums) {
		int n = nums.length;
		int[] dp = new int[n+2];
		dp[0] = 0;
		dp[1] = 0;
		dp[2] = nums[0];
		int max = 0;
		for(int i=3;i<=n;i++) {
			dp[i] = Math.max(dp[i-2]+nums[i-2], dp[i-3]+nums[i-3]);
		}
		if(dp[n]>max) max=dp[n];
		if(nums.length<=1) return nums[0];
		dp[2] = nums[1];
		for(int i=3;i<=n;i++) {
			dp[i] = Math.max(dp[i-2]+nums[i-1], dp[i-3]+nums[i-2]);
		}
		if(dp[n]>max) max=dp[n];
		return max;
    }
}
